import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
// 新增 rootTitle 配置，意思根目录的标题，用来选中下部导航
export const constantRoutes = [{
		path: '/login',
		component: () => import('@/views/login/index'),
		hidden: true
	},

	{
		path: '/404',
		component: () => import('@/views/404'),
		hidden: true
	},

	{
		path: '/',
		component: Layout,
		redirect: '/home',
		children: [{
			path: '/home',
			name: 'Home',
			component: () => import('@/views/home/index'),
			meta: {
				title: '首页',
				rootTitle: '首页'
			}
		}]
	},
	{
		path: '/friends',
		component: Layout,
		redirect: '/friends',
		children: [{
			path: '/friends',
			name: 'Friends',
			component: () => import('@/views/friends/index'),
			meta: {
				title: '资金明细',
				rootTitle: '资金明细'
			}
		}]
	},

	{
		path: '/setting',
		component: Layout,
		redirect: '/setting',
		children: [{
			path: '/setting',
			name: 'Setting',
			component: () => import('@/views/setting/index'),
			meta: {
				title: '设备状态',
				rootTitle: '设备状态',
				once:false
			}
		}]
	},
	{
		path: '/statistics',
		component: Layout,
		redirect: '/statistics',
		children: [{
			path: '/statistics',
			name: 'Statistics',
			component: () => import('@/views/statistics/index'),
			meta: {
				title: '营收统计',
				rootTitle: '营收统计'
			}
		}]
	},
	{
		path: '/refund',
		name: 'refund',
		component: () => import('@/views/statistics/refund/refund'),
		meta: {
			title: '',
			rootTitle: '退款账单'
		}
	},

{
		path: '/monyin',
		name: 'monyin',
		component: () => import('@/views/setting/monyin/monyin'),
		meta: {
			title: '',
			rootTitle: '年费充值'
		}
	},
	{
		path: '/modifyRate',
		name: 'modifyRate',
		component: () => import('@/views/setting/modifyRate/modifyRate'),
		meta: {
			title: '',
			rootTitle: '修改费率'
		}
	},
	{
		path: '/address',
		name: 'address',
		component: () => import('@/views/setting/address/address'),
		meta: {
			title: '',
			rootTitle: '修改地址',
			
		}
	},
	{
		path: '/details',
		name: 'details',
		component: () => import('@/views/statistics/refund/details'),
		meta: {
			title: '',
			rootTitle: '查看详情'
		}
	},
	{
		path: '/gddetails',
		name: 'gddetails',
		component: () => import('@/views/setting/gddetails/gddetails'),
		meta: {
			title: '',
			rootTitle: '工单详情'
		}
	},
	{
		path: '/bindoperations',
		name: 'bindoperations',
		component: () => import('@/views/setting/bindoperations/bindoperations'),
		meta: {
			include:false,
			title: '',
			rootTitle: '绑定运维'
		}
	},
	{
		path: '/my',
		component: Layout,
		redirect: '/my',
		children: [{
			path: '/my',
			name: 'my',
			component: () => import('@/views/my/index'),
			meta: {
				title: '我的',
				rootTitle: '我的'
			}
		}]
	},
	{
		path: '/Password',
		name: 'Password',
		component: () => import('@/views/my/Password/Password'),
		meta: {
			title: '',
			rootTitle: '修改密码'
		}
	},
	{
		path: '/paymony',
		name: 'paymony',
		component: () => import('@/views/my/paymony/paymony'),
		meta: {
			title: '',
			rootTitle: '提现申请'
		}
	},
	// 404 page must be placed at the end !!!
	{
		path: '*',
		redirect: '/404',
		hidden: true
	}
]

const createRouter = () => new Router({
	mode: 'history', // require service support
	scrollBehavior: () => ({
		y: 0
	}),
	routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
	const newRouter = createRouter()
	router.matcher = newRouter.matcher // reset router
}

export default router
